package t_208

type Trie struct {
	isEnd    bool
	children [26]*Trie
}

func Constructor() Trie {
	return Trie{}
}
func (this *Trie) Insert(word string) {
	for i := range word {
		index := word[i] - 'a'
		if this.children[index] == nil {
			this.children[index] = &Trie{}
		}
		this = this.children[index]
	}
	this.isEnd = true
}

func (this *Trie) Search(word string) bool {
	for i := range word {
		index := word[i] - 'a'
		if this.children[index] == nil {
			return false
		}
		this = this.children[index]
	}
	return this.isEnd
}

func (this *Trie) StartsWith(prefix string) bool {
	for i := range prefix {
		index := prefix[i] - 'a'
		if this.children[index] == nil {
			return false
		}
		this = this.children[index]
	}
	return true
}
